import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'library_books_widget.dart';

class FavoriteLibraryPage extends StatelessWidget {
  const FavoriteLibraryPage({super.key});
  @override
  Widget build(BuildContext context) {
    var favoriteList = context.watch<LibraryBooksState>();
    if (favoriteList.favorites.isEmpty) {
      return Container(
        color: Colors.white,
        child: Center(child: Text('暂无数据')),
      );
    }
    return Scaffold(
      body: Container(
        decoration: BoxDecoration(color: Colors.white),
        width: double.infinity,
        child: Column(
          children: [
            Align(
              alignment: Alignment.topLeft,
              child: Padding(
                padding: const EdgeInsets.all(16),
                child: Text('喜欢的单词:'),
              ),
            ),
            Expanded(
              child: SingleChildScrollView(
                child: SizedBox(
                  width: double.infinity,
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Wrap(
                      direction: Axis.horizontal,
                      alignment: WrapAlignment.start,
                      spacing: 6,
                      runSpacing: 6,
                      children: [
                        for (var word in favoriteList.favorites)
                          Card(
                            color: Colors.white,
                            child: Padding(
                              padding: const EdgeInsets.symmetric(
                                horizontal: 12,
                                vertical: 16,
                              ),
                              child: Text(word.asLowerCase.toString()),
                            ),
                          ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
